
"""
 懒汉式
"""
class MusicPlayer(object):

    cls_instance =  None;

    #记录是否执行过初始化方法
    init_flag = False;
    def __new__(cls, *args, **kwargs):
        print("创建对象分配空间");
        #判断类属性是否是None
        if cls.cls_instance is None:
            #调用父类的方法，为第一个对象分配空间
             cls.cls_instance = super().__new__(cls);

        #cls_instance = cls.cls_instance;
        return cls.cls_instance;

    def __init__(self,product):
        #判断是否执行过初始化动作
        if not MusicPlayer.init_flag:
            print("对象初始化");
            self.product = product;
            MusicPlayer.init_flag = True;
        else:
            return;
